#include "key.h"
#include "delay.h"

void EXTICYR_Init(void)
{
	
	EXTI_InitTypeDef EXTI_InitSturct;
	NVIC_InitTypeDef NVIC_InitSturct;
	GPIO_InitTypeDef GPIO_InitSturct; 
	
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOF|RCC_APB2Periph_AFIO,ENABLE);
	GPIO_InitSturct.GPIO_Pin=GPIO_Pin_13;
	GPIO_InitSturct.GPIO_Mode=GPIO_Mode_IPU;
	GPIO_InitSturct.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOC,&GPIO_InitSturct);

	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
	EXTI_InitSturct.EXTI_Line=EXTI_Line13;
	EXTI_InitSturct.EXTI_LineCmd=ENABLE;
	EXTI_InitSturct.EXTI_Mode=EXTI_Mode_Interrupt;
	EXTI_InitSturct.EXTI_Trigger=EXTI_Trigger_Falling;
	EXTI_Init(&EXTI_InitSturct);
	
	

	NVIC_InitSturct.NVIC_IRQChannel=EXTI15_10_IRQn;
	NVIC_InitSturct.NVIC_IRQChannelCmd=ENABLE;
	NVIC_InitSturct.NVIC_IRQChannelPreemptionPriority=1;
	NVIC_InitSturct.NVIC_IRQChannelSubPriority=1;
	NVIC_Init(&NVIC_InitSturct);
	
	
}


void EXTI15_10_IRQHandler(void)
{
	static u8 flag=0;
	delay_ms(10);
	if(EXTI_GetITStatus(EXTI_Line13)==1)
	{
		InitWave(flag);
		flag=!flag;
		EXTI_ClearITPendingBit(EXTI_Line13);
	}

}

